home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / os2 / srefv112.zip / SREFPRC1.ZIP / DOVIRT.SRF < prev    next >
Text File  |  1996-05-11  |  5KB  |  176 lines

  1. /******************************************************************************/
  2. /* ------------------------------------------------------------------------ */
  3. /* DO_VIRTUAL_FILE: Convert from URL to file name-- add virtual directory of data directory.
  4.     ddir : data directory
  5.     sel : request string (after sre-filter has modified it)
  6.     virtual_dir : List of virtual file replacement possiblities.
  7.           virtual_dir.label.nv      virtual_dir.dir.nv      virtual_dir.subok
  8.     Return: file name (with drive/directory) or 0 if not found/not allowed
  9. */
  10.  
  11. sref_do_VIRTUAL:
  12. parse upper arg  ddir,action , macrospace_input ,virtual_file
  13. macrospace_input=strip(macrospace_input)
  14. virtual_file=strip(virtual_file)
  15. ddir=strip(ddir)
  16. action=strip(action)
  17.  
  18. if abbrev(translate(macrospace_input),'N')=1 then macrospace_input=0
  19.  
  20. /* check for illegal action (with .. in it) */
  21. if pos("..",action)>0 then return 0
  22.  
  23.  
  24. filelines.0=0
  25. action=translate(action) ; action=strip(action,'l','/')
  26.  
  27. call get_virtfile 1
  28.  
  29. if filelines.0=0 then do
  30.    return 0                     /*let caller figure out what to do */
  31.  
  32. /* like this. ..
  33.    t1=translate(ddir,'\','/') ;
  34.    tryf=strip(t1,'t','\')||'\'||action
  35.    return tryf
  36. */
  37.  
  38. end
  39.  
  40. gotit=0
  41. do ii =1 to filelines.0
  42.   aline=filelines.ii
  43.   parse upper var aline alabel adir
  44.   subdirs=0
  45.   ifoo=pos('*',adir)
  46.   if ifoo>0 then do
  47.           subdirs=1
  48.           adir=delstr(adir,ifoo)
  49.   end
  50.   alabel=strip(translate(strip(alabel),'/','\'),,'/')||'/'
  51.   adir=strip(translate(strip(adir),'\','/'),'t','\')||'\'
  52.   mdir=filespec('p',adir)
  53.   mdrv=filespec('d',adir)
  54.   if drv="" then drv=filespec('d',ddir)
  55.   adir=mdrv||mdir
  56.  
  57. /* subdirs: allow subdirectory acces
  58.    alabel: the abbrev to match to
  59.    adir: The dir to use instead of alabel
  60. */
  61.  
  62.   if abbrev(action,alabel)=1 then do
  63.          t1=delstr(action,1,length(alabel))
  64.          t1=translate(t1,'\','/')
  65.          tryfile=adir||t1
  66.          if subdirs=1 then do
  67.              gotit=1
  68.              leave
  69.          end
  70.          else do
  71.             if pos('\',t1)>0 then do
  72.                  iterate                /* violation of no subdirs */
  73.             end
  74.             else do
  75.                gotit=1
  76.                leave
  77.              end
  78.          end
  79.    end
  80. end
  81. /*  append to data dir ? */
  82.  if gotit=0 then do
  83.       t1=strip(strip(translate(ddir,'\','/')),,'\')||'\'
  84.       action=translate(action,'\','/')
  85.       action=strip(action,'l','\')
  86.       tryfile=t1||action
  87.  end
  88.  
  89.  tryfile=translate(tryfile,'\','/')
  90.  
  91.  if gotit=1 then
  92.     say " Virtual directory replacement yields: " tryfile
  93.  
  94.  
  95.  return  tryfile  /* success */
  96.  
  97. /* ---------------------------------------------- */
  98.  
  99. get_virtfile:
  100.  
  101. macrodate=0 ; filedate=0
  102. crlf='0d0a'x
  103. if macrospace_input=0  then              /* if no macro space input */
  104.    signal no_macro1
  105.  
  106. signal on error name no_macro1           /* which macro */
  107. signal on syntax name no_macro1
  108. gotit=0 ; macrodate=0
  109. somestuff=sref_macro_virtual()
  110. if somestuff<>0 then
  111.    parse var somestuff macrodate "," somestuff
  112. else
  113.    macrodate=0
  114.  
  115. gotit=1
  116.  
  117. no_macro1:
  118. signal off syntax ; signal off error ;
  119.  
  120. if gotit=1 then signal macrookay
  121.  
  122. /* not in marospace, read from file ? */
  123. if virtual_file="" then do      /* nowhere! */
  124.   filelines.0=0
  125.   return 0
  126. end
  127. say " VIRTUAL files not in macrospace, trying: " virtual_file
  128.  
  129. macrookay:              /* in macro space, or virtual_file exists */
  130. signal off error ; signal off syntax
  131.  
  132. /* get date of file */
  133. if virtual_file<>"" then do
  134.    eek=sysfiletree(translate(virtual_file,'\','/'),'gosh','FT')
  135.    if gosh.0=0 then do  /* no user defined replacement strings */
  136.       say " Missing or unavailable virtual dir file = " virtual_file
  137.       filelines.0=0
  138.       return 0
  139.     end
  140.     parse var gosh.1  atime .
  141.     filedate=sref_juldate('F',atime)
  142. end
  143. else do                 /* no file, force use of macrospace */
  144.      filedate=-1
  145. end
  146. /* use newer one */
  147.  if filedate>=macrodate then do  /* if file newer then macrospace, use file */
  148.       ause=fileread(virtual_file,'templines',,'e')
  149.       if (ause=0) then  do               /*no such file,*/
  150.          say " Missing or unavailable initialization file: " atype
  151.          filelines.0=0
  152.          return 0
  153.       end                        /* so no user defined replacement strings*/
  154.  end
  155.  else do                 /* use stuff stored in macro space */
  156.      i1=0
  157.      do until somestuff=""
  158.          i1=i1+1
  159.          parse var somestuff templines.i1 (crlf) somestuff
  160.       end
  161.       templines.0=i1
  162.   end
  163.  
  164. iff=0
  165. do mm=1 to templines.0
  166.   aline=translate(strip(templines.mm))
  167.   if left(aline,1)=';' | aline="" then iterate
  168.   iff=iff+1
  169.   filelines.iff=templines.mm
  170. end
  171. filelines.0=iff
  172. return iff
  173.  
  174.  
  175.  
  176.